﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UDDL.Model
{
	public class Namespace : Item
	{
		internal Namespace()
			: this(null, "")
		{
		}

		private Namespace(Namespace parent, String name)
			: base(name)
		{
			Parent = parent;
		}

		public Namespace GetNamespace(String name)
		{
			Item item = GetSubItem(name);
			Namespace ns = item as Namespace;
			if (item == null)
			{
				ns = new Namespace(this, name);
				AddSubItem(ns);
				m_subNamespaces.Add(ns);
			}
			else
			{
				ns = item as Namespace;
			}
			return ns;
		}

		public Entity GetEntity(String name)
		{
			Item item = GetSubItem(name);
			Entity entity = item as Entity;
			if (item == null)
			{
				entity = new Entity(this, name);
				AddSubItem(entity);
				m_entities.Add(entity);
			}
			else
			{
				entity = item as Entity;
			}
			return entity;
		}

		public Namespace Parent { get; private set; }
		public IEnumerable<Namespace> SubNamespaces
		{
			get
			{
				return m_subNamespaces.AsReadOnly();
			}
		}
		public IEnumerable<Entity> Entities
		{
			get
			{
				return m_entities.AsReadOnly();
			}
		}
		private List<Namespace> m_subNamespaces = new List<Namespace>();
		private List<Entity> m_entities = new List<Entity>();

	}
}
